package test_PropertyChangeSupport_Class;

import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;

public class MyBoundBean implements PropertyChangeListener {
	String name = "zhangsan";
	int eage = 10;

	private PropertyChangeSupport changes = new PropertyChangeSupport(this);

	public void setString(String newString) {
		addPropertyChangeListener();
		String oldString = name;
		name = newString;
		changes.firePropertyChange("name", oldString, newString);
		removePropertyChangeListener();
	}

	public String getString() {
		return name;
	}

	public void addPropertyChangeListener() {
		changes.addPropertyChangeListener(this);
	}

	public void removePropertyChangeListener() {
		changes.removePropertyChangeListener(this);
	}

	@Override
	public void propertyChange(PropertyChangeEvent evt) {
		if (evt.getPropertyName().equals("name")) {
			this.eage = 20;
			System.out.println("eage:=" + eage);
		}
	}
}